<template>
  <div>
    <el-select v-model="itemAttr.value" :multiple="itemAttr.multiple" clearable
               :style="'width:'+(typeof(itemAttr.width)==='undefined'?width:itemAttr.width)+ 'px'">
      <el-option
        key="#"
        label="无"
        value="#">
      </el-option>
      <el-option
        v-for="rItem in options"
        :key="rItem.id"
        :label="rItem.name"
        :value="rItem.id">
      </el-option>
    </el-select>
  </div>
</template>

<style lang="scss">

</style>

<script>
  export default {
    name: 'LemonESelect',
    props: {
      width: String,
      itemAttr: Object
    },
    created() {
      this.selectList()
    },
    data() {
      return {
        options: []
      }
    },
    methods: {
      selectList(param, callback) {
        if (typeof(this.itemAttr.selectListMethod) === 'undefined') {
          this.options = this.itemAttr.options
        } else {
          //param：搜索参数
          this.itemAttr.selectListMethod(typeof(param) === 'undefined' ? {} : param, (res) => {
            this.options = res
            //若有回调函数，调用回调
            if (typeof(callback) != 'undefined') {
              callback()
            }
          }, () => {
          })
        }
      }

    }
  }
</script>
